extends BTAction

# 节点进入时触发技能释放
func _enter() -> void:
	var unit: Unit = agent
	var target = unit.current_target
	
	# 防御性检查
	if is_instance_valid(unit) and is_instance_valid(target):
		unit.use_skill()


# 持续检测攻击状态
func _tick(_delta: float) -> Status:
	var unit: Unit = agent
	var is_attacking: bool = unit.is_attacking
	
	# 状态检测
	if not is_attacking:
		return Status.SUCCESS
	
	# 额外有效性检查
	var target = unit.current_target
	if not is_instance_valid(target):
		unit.is_attacking = false
		return Status.FAILURE
	
	return Status.RUNNING
